<script setup>
//  按需引入 echarts
import * as echarts from "echarts";

const dom = ref(); // 使用ref创建虚拟DOM引用，使用时用main.value

const { option, height, width } = defineProps({
	option: {
		type: Object,
		defalut: () => ({}),
	},
	height: {
		type: String,
		defalut: "400px",
	},
	width: {
		type: String,
		defalut: "500px",
	},
});

onMounted(() => {
	var myChart = echarts.init(dom.value);
	myChart.setOption(option);
	window.addEventListener("resize", () => {
		myChart.resize();
	});
});

const style = computed(() => ({
	height,
	width,
}));
</script>

<template>
	<div ref="dom" :style="style"></div>
</template>
